﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using net.windward.util;
using System.Xml;
using Microsoft.SharePoint.Administration;
using System.Globalization;
using Microsoft.SharePoint;
using System.IO;
using System.Data.SqlClient;
using System.Data;
using net.windward;
using log4net;

namespace ArrowWebParts
{
    /// <summary>
    /// Provides static methods for reading and enforcing the Arrow license.
    /// </summary>
    public static class ArrowLicenseHandler
    {
        private static ILog _log = LogManager.GetLogger(typeof(ArrowLicenseHandler));

        #region licensing properties
        /// <summary>
        /// ArrowLicense appSetting key name.
        /// </summary>
        public static readonly string APPSETTING_ARROW_LICENSE = "ArrowLicense";
        /// <summary>
        /// The wr.license java property key name.
        /// </summary>
        public static readonly string JAVA_PROP_WR_LICENSE = "wr.license";
        #endregion licensing properties

        /// <summary>
        /// Reads the license from SPFarm.Local.Properties["WindwardArrowLicense"].
        /// Does not depend on SPContext or HttpContext.
        /// </summary>
        /// <returns></returns>
        public static string ReadLicense()
        {
            return (string)SPFarm.Local.Properties["WindwardArrowLicense"];
        }
        /// <summary>
        /// Loads the wr.license property with the specified Arrow license.
        /// </summary>
        /// <param name="strLicense">the Arrow license</param>
        public static void LoadJavaLicenseProperty(string strLicense)
        {
            // stuff wr.license with license string
            java.util.Properties props = java.lang.System.getProperties();
            props.put(JAVA_PROP_WR_LICENSE, strLicense);
            java.lang.System.setProperties(props);
        }
    }
}
